package com.wangsd.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class SMSUtils {

    /**
     * 线上线下平台发送短信
     * @param mobile
     * @return
     */
    public static JSONObject sendXSXXsms(String mobile, String msg) {
        JSONObject jsonObject = sendXSXXsmsPlus(mobile, msg, "注册验证码");
        return jsonObject;
    }


    /**
     * 线上线下平台发送短信
     * @param mobile
     * @return
     */
    public static JSONObject sendXSXXsmsPlus(String mobile, String msg,String msgTitle) {
        if(msgTitle == null){
            msgTitle = "码商系统";
        }
        JSONObject retObj = null;
        String url = "http://43.254.52.253:8088/websms/smsJsonService";
        Map<String, String> postData = new HashMap<>();
        postData.put("action", "sendsms");
        postData.put("userId", "cqsyl01hyhy");
        postData.put("md5password", MD5Utils.MD5Encode("542550","UTF-8"));
        postData.put("content", "【"+msgTitle+"】"+msg);
        postData.put("mobile", mobile);
        //postData.put("msgId", "1543202389117");
        try {
            String str = HttpClientUtils.post(url, postData);
            retObj = JSON.parseObject(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return retObj;
    }

    public static void main(String[] args) {
        JSONObject jsonObject = sendXSXXsms("19923832160", new Random().nextInt(999999)+"");
        System.out.println(JSON.toJSONString(jsonObject));
    }
}
